package file_info

import (
	"errors"
	"os"
)

const (
	NormalAction Tag = iota
	OnlyDelete

	unknown
)

type Tag int

type FileInfo struct {
	fileInfo os.FileInfo
	filePath string
	hash     string
	tag      Tag
}

func NewFileInfo(osFileInfo os.FileInfo, filePath, hash string) *FileInfo {
	return &FileInfo{
		fileInfo: osFileInfo,
		filePath: filePath,
		hash:     hash,
		tag:      NormalAction,
	}
}

func (f FileInfo) Path() string {
	return f.filePath
}

func (f FileInfo) Hash() string {
	return f.hash
}

func (f FileInfo) Size() int64 {
	return f.fileInfo.Size()
}

func (f FileInfo) Info() os.FileInfo {
	return f.fileInfo
}

func (f FileInfo) Sys() interface{} {
	return f.fileInfo.Sys()
}

func (f *FileInfo) SetHash(hash string) {
	f.hash = hash
}

func (f *FileInfo) SetTag(tag Tag) error {
	if tag < NormalAction || tag >= unknown {
		return errors.New("unknown tag")
	}
	f.tag = tag
	return nil
}

func (f *FileInfo) GetTag() Tag {
	return f.tag
}
